Page({
  data: {
    news: {
      id: 1,
      title: 'iPhone 15 Pro Max 钛金属版本即将发布',
      tag: '新品',
      time: '2023-12-20',
      imageUrl: '/assets/images/2.jpg',
      content: '将于本月底开启预售，敬请期待。',
      images: [
        '/assets/images/1.jpg',
        '/assets/images/2.jpg',
        '/assets/images/3.jpg'
      ],
      related: [
        {
          id: 2,
          title: 'iOS 17.2 正式版发布，带来全新日记应用',
          tag: '资讯'
        },
        {
          id: 3,
          title: 'iPhone 15 系列保护壳新品上市',
          tag: '配件'
        }
      ]
    }
  },

  onLoad(options) {
    const newsId = options.id
    this.loadNewsDetail(newsId)
  },

  // 加载新闻详情
  loadNewsDetail(newsId) {
    // TODO: 从服务器加载新闻详情
    console.log('加载新闻ID：', newsId)
  },

  // 预览图片
  previewImage(e) {
    const current = e.currentTarget.dataset.url
    wx.previewImage({
      current,
      urls: this.data.news.images
    })
  },

  // 点击相关新闻
  onRelatedTap(e) {
    const newsId = e.currentTarget.dataset.id
    wx.redirectTo({
      url: `/pages/news/detail?id=${newsId}`
    })
  },

  // 分享
  onShareAppMessage() {
    const { title, imageUrl } = this.data.news
    return {
      title,
      imageUrl,
      path: `/pages/news/detail?id=${this.data.news.id}`
    }
  }
}) 